package com.boyunv.bridge;

/*
 *@description  -------
 *静态代理:
 *     优点:  在不修改目标类的前提下,扩展目标类的功能
 *      缺点:   冗余  不易维护
 *@author boyunv
 *@create 2023/7/2 9:25
 *@version 1.0
 */
import com.boyunv.bridge.example01.IUserDao;
import com.boyunv.bridge.example01.UserDaoImpl;
import com.boyunv.bridge.example01.UserDaoProxy;
import com.boyunv.bridge.example02.ProxyFactory;
import org.junit.Test;
public class TestProxy {
    @Test
    public  void  testStaticProxy(){
        //目标类
        IUserDao dao = new UserDaoImpl();
        //代理对象
        UserDaoProxy proxy=new UserDaoProxy(dao);

        proxy.save();

    }

    public static void main(String[] args) {
        IUserDao dao=new UserDaoImpl();
        //目标对象的信息
        System.out.println(dao.getClass());
        //获取代理对象
        IUserDao proxyInstance =(IUserDao) new ProxyFactory(dao).getProxyInstance();
        System.out.println(proxyInstance.getClass());
        proxyInstance.save();//代理方法


    }
}
